"""商品类目列表"""
import time

from selenium.webdriver.common.by import By

from dianzishangwu_testing.page_objects.base_page import BasePage


class CategoryListPage(BasePage):
    __ADD_BUTTON = (By.XPATH, "//*[text()='添加']/..")
    __ADD_MESSAGE_BOX = (By.XPATH, "//*[text()='创建成功']")
    __DEL_MESSAGE_BOX = (By.XPATH, "//*[text()='删除成功']")

    """添加操作"""

    def click_add(self):
        self.do_find(self.__ADD_BUTTON).click()

        from dianzishangwu_testing.page_objects.category_create_page import CategoryCreatePage
        return CategoryCreatePage(self.driver)

    """获取添加操作结果"""

    def get_add_result(self):
        self.wait_element_until(self.__ADD_MESSAGE_BOX)
        msg = self.do_find(self.__ADD_MESSAGE_BOX).text

        return msg

    def click_delete(self, category_name):
        # time.sleep(2)
        # self.do_find(By.XPATH, f"//*[text()='{category_name}']/../..//*[text()='删除']").click()
        self.wait_element_click((By.XPATH, f"//*[text()='{category_name}']/../..//*[text()='删除']")).click()
        return CategoryListPage(self.driver)

    def get_delete_result(self):
        self.wait_element_until(self.__DEL_MESSAGE_BOX)
        msg = self.do_find(self.__DEL_MESSAGE_BOX).text
        return msg